package com.dao;

import com.entity.Good;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * GoodDao层
 * 包含商品查询全部、分类别商品查询、商品添加、商品销售（修改）、商品删除、商品模糊查询
 */
public interface GoodDao {

    /**
     * 查询全部商品
     */
    @Select("select * from goods")
    public List<Good> findAll();

    /**
     * 查询食品商品
     */
    @Select("select * from goods where kind = 0")
    public List<Good> findFood();

    /**
     * 查询饮料商品
     */
    @Select("select * from goods where kind = 3")
    public List<Good> findDrink();

    /**
     * 查询日用品商品
     */
    @Select("select * from goods where kind = 2")
    public List<Good> findNess();

    /**
     * 查询化妆品商品
     */
    @Select("select * from goods where kind = 1")
    public List<Good> findCos();

    /**
     * 添加商品
     */
    @Insert("insert into goods value(#{name},#{charge},#{amount},#{factory},#{mark},#{oth},#{kind})")
    public void addGood(Good good);

    /**
     * 通过名字查询商品
     */
    @Select("select * from goods where name like #{name}")
    public List<Good> findByName(String name);

    /**
     * 根据名称删除商品
     */
    @Delete("delete from goods where name = #{name}")
    public void deleteGood(String name);

    /**
     * 修改商品信息
     */
    @Update("update goods set " +
            "charge = #{charge},amount=#{amount},factory=#{factory},mark=#{mark},oth=#{oth},kind=#{kind} " +
            "where name = #{name}")
    public void updateGood(Good good);

    /**
     * 售卖商品
     */
    @Update("update goods set amount=#{amount} where name = #{name}")
    public void sellGood(@Param("name") String name,@Param("amount") int amount);
}
